#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 1e4 + 10, M = N * 2;
int h[N], e[M], ne[M], w[M], idx;
int dis[N], ans[M], st[N];
int p[N];
int n, m;
vector<PII>query[N];
void add(int a, int b, int c)
{
	e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
int find(int x)
{
	if (x != p[x]) {
		p[x] = find(p[x]);
	}
	return p[x];
}
void dfs(int u, int father)
{
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j != father) {
			dis[j] = dis[u] + w[i];
			dfs(j, u);
			//cout << "u--->j--->dis[u]====" << u << "  " << j << "  " << dis[u] << endl;
		}
	}
}

void tarjan(int u)
{
	st[u] = 1;
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (!st[j]) {
			tarjan(j);
			p[j] = u;
		}
	}

	for (auto item : query[u]) {
		int x = item.x, y = item.y;
		if (st[x] == 2) {
			int root = find(x);
			ans[y] = dis[u] + dis[x] - 2 * dis[root];
		}
	}
	st[u] = 2;
}
int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof(h));
	for (int i = 0; i < n - 1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		add(a, b, c);
		add(b, a, c);
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if (a != b) {
			query[a].push_back({ b,i });
			query[b].push_back({ a,i });
		}
	}
	for (int i = 1; i <= n; i++)p[i] = i;
	dfs(1, 0);
	tarjan(1);
	for (int i = 0; i < m; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}